*******************************************************************
*Replication code for
*	Article: COVID 19 infection induces higher trust in strangers
*	Journal: PNAS
*	Authors: Diego Gambetta and Davide Morisi
*******************************************************************

*TREND OVER TIME

*Set working directory
cd "[your working directory]"

*open data
use "Replication\Data\swg_panel_replication", clear


************
*Wave 0 (before pandemic)

gen wave = 0 if trust_itr_pre01!=. // only people who replied to trust in Italians before pandemic
gen wave_panel = 0 if panel==4 & trust_itr_pre01!=.

gen group_trend = 1 if covid_ind==0 & w2_covid_ind==0 & w3_covid_ind==0
replace group_trend = 2 if covid_ind==1 & w2_covid_ind==0 & w3_covid_ind==0
replace group_trend = 3 if covid_ind==1 & w2_covid_ind==1 & w3_covid_ind==0
replace group_trend = 4 if covid_ind==1 & w2_covid_ind==0 & w3_covid_ind==1
replace group_trend = 5 if covid_ind==0 & w2_covid_ind==1 & w3_covid_ind==0
replace group_trend = 6 if covid_ind==0 & w2_covid_ind==0 & w3_covid_ind==1
replace group_trend = 7 if covid_ind==0 & w2_covid_ind==1 & w3_covid_ind==1
replace group_trend = 8 if covid_ind==1 & w2_covid_ind==1 & w3_covid_ind==1
label de group_trend 1"no, no, no" 2"yes, no, no" 3"yes, yes, no" 4"yes, no, yes" ///
5"no, yes, no" 6"no, no, yes" 7"no, yes, yes" 8"yes, yes, yes"
label var group_trend "Suffered from covid in w1, w2, w3?"
label val group_trend group_trend
fre group_trend

clonevar trust_stranger_trend = trust_stranger

clonevar covid_ind_trend = covid_ind
clonevar covid_family_trend = covid_family4
clonevar covid_friends_trend = covid_friends4
clonevar covid_colleague_trend = covid_colleague4
clonevar incr_trend = incr_mar_apr2020_w5

clonevar live_alone_trend = w1_live_alone
clonevar perceived_eco2_trend = w1_perceived_eco2

*trust pre pandemic
clonevar w0_trust_it01 = trust_itr_pre01
*trust in Italians
clonevar trust_it_trend = w0_trust_it01

*replied to question on trust in Italians?
gen w0_trust_it_filter = 0
replace w0_trust_it_filter = 1 if w0_trust_it01!=.
gen w2_trust_it_filter = 0
replace w2_trust_it_filter = 1 if w2_trust_it01!=.
gen w3_trust_it_filter = 0
replace w3_trust_it_filter = 1 if w3_trust_it01!=.
fre w*_trust_it_filter

gen trust_it_reply = 0 if w0_trust_it01==. & w2_trust_it01==. & w3_trust_it01==.
replace trust_it_reply = 1 if w0_trust_it01!=. & w2_trust_it01==. & w3_trust_it01==.
replace trust_it_reply = 2 if w0_trust_it01==. & w2_trust_it01!=. & w3_trust_it01==.
replace trust_it_reply = 3 if w0_trust_it01==. & w2_trust_it01==. & w3_trust_it01!=.
replace trust_it_reply = 4 if w0_trust_it01!=. & w2_trust_it01!=. & w3_trust_it01==.
replace trust_it_reply = 5 if w0_trust_it01!=. & w2_trust_it01==. & w3_trust_it01!=.
replace trust_it_reply = 6 if w0_trust_it01==. & w2_trust_it01!=. & w3_trust_it01!=.
replace trust_it_reply = 7 if w0_trust_it01!=. & w2_trust_it01!=. & w3_trust_it01!=.
label de trust_it_reply  0"never replied" ///
1"only before pandemic" ///
2"only in w2" ///
3"only in w3" ///
4"only in w0 & w2" ///
5"only in w0 & w3" ///
6"only in w2 & w3" ///
7 "in all waves"
label var trust_it_reply  "Replied to question on trust in Italians?"
label val trust_it_reply trust_it_reply
fre trust_it_reply 

gen pre_pandemic_trust = 0
replace pre_pandemic_trust = 1 if w0_trust_it01!=. 
fre pre_pandemic_trust

save "Replication\Data\trust_trend_w0", replace


*********
*Wave 1
use "Replication\Data\swg_panel_replication", clear

gen wave = 1 if panel_w1==1
gen wave_panel = 1 if panel==4

gen group_trend = 1 if covid_ind==0 & w2_covid_ind==0 & w3_covid_ind==0
replace group_trend = 2 if covid_ind==1 & w2_covid_ind==0 & w3_covid_ind==0
replace group_trend = 3 if covid_ind==1 & w2_covid_ind==1 & w3_covid_ind==0
replace group_trend = 4 if covid_ind==1 & w2_covid_ind==0 & w3_covid_ind==1
replace group_trend = 5 if covid_ind==0 & w2_covid_ind==1 & w3_covid_ind==0
replace group_trend = 6 if covid_ind==0 & w2_covid_ind==0 & w3_covid_ind==1
replace group_trend = 7 if covid_ind==0 & w2_covid_ind==1 & w3_covid_ind==1
replace group_trend = 8 if covid_ind==1 & w2_covid_ind==1 & w3_covid_ind==1
label de group_trend 1"no, no, no" 2"yes, no, no" 3"yes, yes, no" 4"yes, no, yes" ///
5"no, yes, no" 6"no, no, yes" 7"no, yes, yes" 8"yes, yes, yes"
label var group_trend "Suffered from covid in w1, w2, w3?"
label val group_trend group_trend
fre group_trend

clonevar trust_stranger_trend = trust_stranger

clonevar covid_ind_trend = covid_ind
clonevar covid_family_trend = covid_family4
clonevar covid_friends_trend = covid_friends4
clonevar covid_colleague_trend = covid_colleague4
clonevar incr_trend = incr_mar_apr2020_w5

clonevar live_alone_trend = w1_live_alone
clonevar perceived_eco2_trend = w1_perceived_eco2

*trust pre pandemic
clonevar w0_trust_it01 = trust_itr_pre01

*replied to question on trust in Italians?
gen w0_trust_it_filter = 0
replace w0_trust_it_filter = 1 if w0_trust_it01!=.
gen w2_trust_it_filter = 0
replace w2_trust_it_filter = 1 if w2_trust_it01!=.
gen w3_trust_it_filter = 0
replace w3_trust_it_filter = 1 if w3_trust_it01!=.
fre w*_trust_it_filter

gen trust_it_reply = 0 if w0_trust_it01==. & w2_trust_it01==. & w3_trust_it01==.
replace trust_it_reply = 1 if w0_trust_it01!=. & w2_trust_it01==. & w3_trust_it01==.
replace trust_it_reply = 2 if w0_trust_it01==. & w2_trust_it01!=. & w3_trust_it01==.
replace trust_it_reply = 3 if w0_trust_it01==. & w2_trust_it01==. & w3_trust_it01!=.
replace trust_it_reply = 4 if w0_trust_it01!=. & w2_trust_it01!=. & w3_trust_it01==.
replace trust_it_reply = 5 if w0_trust_it01!=. & w2_trust_it01==. & w3_trust_it01!=.
replace trust_it_reply = 6 if w0_trust_it01==. & w2_trust_it01!=. & w3_trust_it01!=.
replace trust_it_reply = 7 if w0_trust_it01!=. & w2_trust_it01!=. & w3_trust_it01!=.
label de trust_it_reply  0"never replied" ///
1"only before pandemic" ///
2"only in w2" ///
3"only in w3" ///
4"only in w0 & w2" ///
5"only in w0 & w3" ///
6"only in w2 & w3" ///
7 "in all waves"
label var trust_it_reply  "Replied to question on trust in Italians?"
label val trust_it_reply trust_it_reply
fre trust_it_reply 

gen pre_pandemic_trust = 0
replace pre_pandemic_trust = 1 if w0_trust_it01!=. 
fre pre_pandemic_trust

save "Replication\Data\trust_trend_w1", replace


*****
*Wave 2
use "Replication\Data\swg_panel_replication", clear

gen wave = 2 if panel_w2==1
gen wave_panel = 2 if panel==4

gen group_trend = 1 if covid_ind==0 & w2_covid_ind==0 & w3_covid_ind==0
replace group_trend = 2 if covid_ind==1 & w2_covid_ind==0 & w3_covid_ind==0
replace group_trend = 3 if covid_ind==1 & w2_covid_ind==1 & w3_covid_ind==0
replace group_trend = 4 if covid_ind==1 & w2_covid_ind==0 & w3_covid_ind==1
replace group_trend = 5 if covid_ind==0 & w2_covid_ind==1 & w3_covid_ind==0
replace group_trend = 6 if covid_ind==0 & w2_covid_ind==0 & w3_covid_ind==1
replace group_trend = 7 if covid_ind==0 & w2_covid_ind==1 & w3_covid_ind==1
replace group_trend = 8 if covid_ind==1 & w2_covid_ind==1 & w3_covid_ind==1
label de group_trend 1"no, no, no" 2"yes, no, no" 3"yes, yes, no" 4"yes, no, yes" ///
5"no, yes, no" 6"no, no, yes" 7"no, yes, yes" 8"yes, yes, yes"
label var group_trend "Suffered from covid in w1, w2, w3?"
label val group_trend group_trend
fre group_trend

clonevar trust_stranger_trend = w2_trust_stranger

clonevar covid_ind_trend = w2_covid_ind
clonevar covid_family_trend = w2_covid_family4
clonevar covid_friends_trend = w2_covid_acq_fr4
clonevar covid_colleague_trend = w2_covid_col4
clonevar incr_trend = incr_sep_oct2020_w5

clonevar live_alone_trend = w2_live_alone
clonevar perceived_eco2_trend = w2_perceived_eco2

*trust pre pandemic
clonevar w0_trust_it01 = trust_itr_pre01
*trust in Italians
clonevar trust_it_trend = w2_trust_it01

*replied to question on trust in Italians?
gen w0_trust_it_filter = 0
replace w0_trust_it_filter = 1 if w0_trust_it01!=.
gen w2_trust_it_filter = 0
replace w2_trust_it_filter = 1 if w2_trust_it01!=.
gen w3_trust_it_filter = 0
replace w3_trust_it_filter = 1 if w3_trust_it01!=.
fre w*_trust_it_filter

gen trust_it_reply = 0 if w0_trust_it01==. & w2_trust_it01==. & w3_trust_it01==.
replace trust_it_reply = 1 if w0_trust_it01!=. & w2_trust_it01==. & w3_trust_it01==.
replace trust_it_reply = 2 if w0_trust_it01==. & w2_trust_it01!=. & w3_trust_it01==.
replace trust_it_reply = 3 if w0_trust_it01==. & w2_trust_it01==. & w3_trust_it01!=.
replace trust_it_reply = 4 if w0_trust_it01!=. & w2_trust_it01!=. & w3_trust_it01==.
replace trust_it_reply = 5 if w0_trust_it01!=. & w2_trust_it01==. & w3_trust_it01!=.
replace trust_it_reply = 6 if w0_trust_it01==. & w2_trust_it01!=. & w3_trust_it01!=.
replace trust_it_reply = 7 if w0_trust_it01!=. & w2_trust_it01!=. & w3_trust_it01!=.
label de trust_it_reply  0"never replied" ///
1"only before pandemic" ///
2"only in w2" ///
3"only in w3" ///
4"only in w0 & w2" ///
5"only in w0 & w3" ///
6"only in w2 & w3" ///
7 "in all waves"
label var trust_it_reply  "Replied to question on trust in Italians?"
label val trust_it_reply trust_it_reply
fre trust_it_reply 

gen pre_pandemic_trust = 0
replace pre_pandemic_trust = 1 if w0_trust_it01!=. 
fre pre_pandemic_trust

save "Replication\Data\trust_trend_w2", replace


****
*w3
use "Replication\Data\swg_panel_replication", clear

gen wave = 3 if panel_w3==1
gen wave_panel = 3 if panel==4

gen group_trend = 1 if covid_ind==0 & w2_covid_ind==0 & w3_covid_ind==0
replace group_trend = 2 if covid_ind==1 & w2_covid_ind==0 & w3_covid_ind==0
replace group_trend = 3 if covid_ind==1 & w2_covid_ind==1 & w3_covid_ind==0
replace group_trend = 4 if covid_ind==1 & w2_covid_ind==0 & w3_covid_ind==1
replace group_trend = 5 if covid_ind==0 & w2_covid_ind==1 & w3_covid_ind==0
replace group_trend = 6 if covid_ind==0 & w2_covid_ind==0 & w3_covid_ind==1
replace group_trend = 7 if covid_ind==0 & w2_covid_ind==1 & w3_covid_ind==1
replace group_trend = 8 if covid_ind==1 & w2_covid_ind==1 & w3_covid_ind==1
label de group_trend 1"no, no, no" 2"yes, no, no" 3"yes, yes, no" 4"yes, no, yes" ///
5"no, yes, no" 6"no, no, yes" 7"no, yes, yes" 8"yes, yes, yes"
label var group_trend "Suffered from covid in w1, w2, w3?"
label val group_trend group_trend
fre group_trend

clonevar trust_stranger_trend = w3_trust_stranger

clonevar covid_ind_trend = w3_covid_ind
clonevar covid_family_trend = w3_covid_family4
clonevar covid_friends_trend = w3_covid_acq_fr
clonevar covid_colleague_trend = w3_covid_col4
clonevar incr_trend = incr_dec_jan2021_w5

clonevar live_alone_trend = w3_live_alone
clonevar perceived_eco2_trend = w3_perceived_eco2

*trust pre pandemic
clonevar w0_trust_it01 = trust_itr_pre01
*trust in Italians
clonevar trust_it_trend = w3_trust_it01

*replied to question on trust in Italians?
gen w0_trust_it_filter = 0
replace w0_trust_it_filter = 1 if w0_trust_it01!=.
gen w2_trust_it_filter = 0
replace w2_trust_it_filter = 1 if w2_trust_it01!=.
gen w3_trust_it_filter = 0
replace w3_trust_it_filter = 1 if w3_trust_it01!=.
fre w*_trust_it_filter

gen trust_it_reply = 0 if w0_trust_it01==. & w2_trust_it01==. & w3_trust_it01==.
replace trust_it_reply = 1 if w0_trust_it01!=. & w2_trust_it01==. & w3_trust_it01==.
replace trust_it_reply = 2 if w0_trust_it01==. & w2_trust_it01!=. & w3_trust_it01==.
replace trust_it_reply = 3 if w0_trust_it01==. & w2_trust_it01==. & w3_trust_it01!=.
replace trust_it_reply = 4 if w0_trust_it01!=. & w2_trust_it01!=. & w3_trust_it01==.
replace trust_it_reply = 5 if w0_trust_it01!=. & w2_trust_it01==. & w3_trust_it01!=.
replace trust_it_reply = 6 if w0_trust_it01==. & w2_trust_it01!=. & w3_trust_it01!=.
replace trust_it_reply = 7 if w0_trust_it01!=. & w2_trust_it01!=. & w3_trust_it01!=.
label de trust_it_reply  0"never replied" ///
1"only before pandemic" ///
2"only in w2" ///
3"only in w3" ///
4"only in w0 & w2" ///
5"only in w0 & w3" ///
6"only in w2 & w3" ///
7 "in all waves"
label var trust_it_reply  "Replied to question on trust in Italians?"
label val trust_it_reply trust_it_reply
fre trust_it_reply 

gen pre_pandemic_trust = 0
replace pre_pandemic_trust = 1 if w0_trust_it01!=. 
fre pre_pandemic_trust

save "Replication\Data\trust_trend_w3", replace


*********
*Combine

use "Replication\Data\trust_trend_w0", clear
append using "Replication\Data\trust_trend_w1"
append using "Replication\Data\trust_trend_w2"
append using "Replication\Data\trust_trend_w3"

fre group_trend wave wave_panel

*individual controls
global demo_basic "i.female age ib2.edu4 i.area"
global demo_trend "i.female age ib2.edu4 i.live_alone_trend ib2.employ1 i.perceived_eco2_trend i.area"

*municipality controls
global demo_geo "log_pop2018 log_dens2018 male_ratio_dec share65plus_dec employ_rate2018_dec"


************
*ANALSYSIS

*invert groups 7 and 6
fre group_trend
recode group_trend 6=7 7=6
label de group_trend2 1"no, no, no" 2"yes, no, no" 3"yes, yes, no" 4"yes, no, yes" ///
5"no, yes, no" 7"no, no, yes" 6"no, yes, yes" 8"yes, yes, yes"
label var group_trend "Suffered from covid in w1, w2, w3?"
label val group_trend group_trend2
fre group_trend


*
*Table D1. Effect of individual exposure to COVID-19 on trust over time
fre wave
eststo clear
*basic
reg trust_stranger_trend i.group_trend##i.wave $demo_basic if wave>0, cluster(TEL_numeric)
eststo model1: margins, dydx(group_trend) at(wave==(1(1)3)) post
*full controls
reg trust_stranger_trend i.group_trend##i.wave c.covid_family_trend c.covid_friends_trend c.covid_colleague_trend c.incr_trend ///
$demo_trend $demo_geo if wave>0, cluster(TEL_numeric)
eststo model2: margins, dydx(group_trend) at(wave==(1(1)3)) post
esttab using "~Table_D1.rtf", ///
b(%6.3f) se(%6.3f) starlevels(+ .1 * .05 ** .01 *** .001)  scalars (r2) title("Table D1") wide compress noeqlines replace


*****************
*Figure 3. Trust in strangers over time (model 1 in Table D1)

*Symptoms in W1/W2 (2 and 3)
eststo clear
reg trust_stranger_trend i.group_trend##i.wave $demo_basic if wave>0, cluster(TEL_numeric)
eststo group1: margins wave, at(group_trend==1) post
reg trust_stranger_trend i.group_trend##i.wave $demo_basic if wave>0, cluster(TEL_numeric)
eststo group2: margins wave, at(group_trend==2) post
reg trust_stranger_trend i.group_trend##i.wave $demo_basic if wave>0, cluster(TEL_numeric)
eststo group3: margins wave, at(group_trend==3) post
*graph
coefplot (group1, recast(connected) level(90 95) label(No symptoms)) ///
 (group2, recast(connected) level(90 95) label(Symptoms in Wave 1 only)) ///
(group3, recast(connected) level(90 95) label(Symptoms in Wave 1 & Wave 2)), yline(0, lpattern(dash) lcolor(gs10)) vert ///
graphregion(color(white)) ytitle("Trust in strangers (wallet question, from 0 to 1)") ///
title("COVID-19 symptoms in Wave 1/Wave 2") name(fig4A, replace) ///
xscale(range(1(1)3)) xlabel(1 "Wave 1" 2"Wave 2" 3"Wave3") 

*Symptoms in W2/W3 (group 5 and 6)
eststo clear
reg trust_stranger_trend i.group_trend##i.wave $demo_basic if wave>0, cluster(TEL_numeric)
eststo group1: margins wave, at(group_trend==1) post
reg trust_stranger_trend i.group_trend##i.wave $demo_basic if wave>0, cluster(TEL_numeric)
eststo group5: margins wave, at(group_trend==5) post
reg trust_stranger_trend i.group_trend##i.wave $demo_basic if wave>0, cluster(TEL_numeric)
eststo group6: margins wave, at(group_trend==6) post
*graph
coefplot (group1, recast(connected) level(90 95) label(No symptoms)) ///
 (group5, recast(connected) level(90 95) label(Symptoms in Wave 2 only)) ///
(group6, recast(connected) level(90 95) label(Symptoms in Wave 2 & Wave 3)), yline(0, lpattern(dash) lcolor(gs10)) vert ///
graphregion(color(white)) ytitle("Trust in strangers (wallet question, from 0 to 1)") ///
title("COVID-19 symptoms in Wave 2/Wave 3") name(fig4B, replace) ///
xscale(range(1(1)3)) xlabel(1 "Wave 1" 2"Wave 2" 3"Wave3") 

*combined
graph combine fig4A fig4B, graphregion(color(white)) ycommon


*****************

*
*Table D2. Changes in trust in Italians in Waves 2 and 3 compared to before pandemic levels
recode group_trend (1=0 "never suffered") (2/8=1 "suffered at least once"), gen(group_trend2)
eststo clear
eststo: reg trust_it_trend i.wave $demo_basic i.group i.year1 if trust_it_reply==7, cluster(TEL_numeric)
eststo: reg trust_it_trend i.wave $demo_trend $demo_geo i.group i.year1 if trust_it_reply==7, cluster(TEL_numeric)
eststo: reg trust_it_trend i.wave##i.group_trend2 $demo_trend $demo_geo i.group i.year1 if trust_it_reply==7, cluster(TEL_numeric)
esttab using "~TableD2.rtf", ///
b(%6.3f) se(%6.3f) starlevels(+ .1 * .05 ** .01 *** .001)  scalars (r2) title("Table D2.") wide compress noeqlines replace



***************
*Figure D1. Average levels of trust in Italians before and during the pandemic

*all respondents
reg trust_it_trend i.wave $demo_trend $demo_geo i.group i.year1 if trust_it_reply==7, cluster(TEL_numeric)
margins wave, post
coefplot, vert graphregion(color(white)) ///
ytitle("Trust in Italians (from 0 to 1)") ///
text(.518 2 "*", color(gs4) orientation(horizontal) placement(6)) ///
text(.518 3 "*", color(gs4) orientation(horizontal) placement(6)) ///
xlabel(1 "Before pandemic" 2"Wave 2" 3"Wave3") ///
title("All respondents") name(figD1_all)

*only those with no symptoms
reg trust_it_trend i.wave##i.group_trend2 $demo_trend $demo_geo i.group i.year1 if trust_it_reply==7, cluster(TEL_numeric)
margins wave, at(group_trend2==0) post
coefplot, vert graphregion(color(white)) ///
ytitle("Trust in Italians (from 0 to 1)") ///
text(.513 2 "*", color(gs4) orientation(horizontal) placement(6)) ///
text(.513 3 "*", color(gs4) orientation(horizontal) placement(6)) ///
xlabel(1 "Before pandemic" 2"Wave 2" 3"Wave3") ///
title("No individual COVID-19 symptoms") name(figD1_no_sympt, replace)

*combined
graph combine figD1_all figD1_no_sympt, graphregion(color(white))



